/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package MetricsRetriever;

import java.util.ArrayList;

/**
 *
 * @author Manuel
 */
public class DataManager {

    private ArrayList<String> links;
    private ArrayList<Project> projects;

    public DataManager(){
        links = new ArrayList<String>();
        projects = new ArrayList<Project>();
    }

    public void addNewProject(Project p){
        projects.add(p);
    }

    public synchronized Project processNextProject(){
        Project current = projects.get(0);
        projects.remove(0);
        return current;
    }

    public void addNewLink(int pos,String link){
        //TODO choose alternating requests
            links.add(link);
    }

    public synchronized String processNextLink(String forge){
        System.out.println(this.getLinksLeft()+" projects to go...");
        for(int i = 0;i<links.size();i++){
            String nextLink = links.get(i);
            if(nextLink.contains(forge)){
                links.remove(i);
                return nextLink;
            }
        }
        return null;
    }

    public int getLinksLeft(){
        return links.size();
    }

    public int getLinksLeft(String forge){
        int counter=0;
        for(int i = 0;i<links.size();i++){
            if(links.get(i).contains(forge))
                counter++;
        }
        return counter;
    }

    public int getProjectsLeft() {
        return projects.size();
    }


}
